package com.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * 38. 书籍叠放
 * https://blog.csdn.net/weixin_48157259/article/details/131454225
 */
public class NiukeMoni38nan {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(",");

        // 得到 书籍 集合
        List<int[]> books = new ArrayList<>();
        for (int i = 0; i < input.length / 2; i++) {
            int[] book = new int[2];
            book[0] = Integer.parseInt(input[2 * i]);
            book[1] = Integer.parseInt(input[2 * i + 1]);
            books.add(book);
        }

        // 按书籍长度从小到大排序，如果书籍长度相同，按宽度从大到小排序
        books.sort(new Comparator<int[]>() {
            @Override
            public int compare(int[] ints, int[] t1) {
                if (ints[0] == t1[0]) {
                    return t1[1] - ints[1];
                }
                return ints[0] - t1[0];
            }
        });

        for (int i = 0; i < books.size(); i++) {
            System.out.println(Arrays.toString(books.get(i)));
        }

        int n = books.size();
        int[] dp = new int[n]; // 选择了第i本书籍为底部书籍，能够叠放的最多数目
        int result = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                /**
                 * 如果书籍i的宽度大于书籍j的宽度，那么书籍j可以放在书籍i的上方。
                 * 如果选择i放在j的下方能使得i叠放更多书籍，则选择j。
                 */
                if (books.get(i)[0] > books.get(j)[0] && books.get(i)[1] > books.get(j)[1]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }

            result = Math.max(result, dp[i] + 1);
        }

        System.out.println(result);

    }

}
